package it.asvp.asvp_portal.data.entity.notification;

import it.asvp.asvp_portal.asvp_util.enumerative.ReceiverOption;
import it.asvp.asvp_portal.data.entity.domain.BaseEntity;
import it.asvp.asvp_portal.data.entity.member.Member;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;

@SuppressWarnings("serial")
@Entity
@Table(name = "notification", catalog = "asvp_db")
public class Notification extends BaseEntity {

  @ManyToOne(fetch = FetchType.LAZY)
  @JoinColumn(name = "sender_id", nullable = false)
  private Member                    member;

  @Column(name = "note", nullable = false, length = 1000)
  private String                    note;

  @Temporal(TemporalType.DATE)
  @Column(name = "start_date", nullable = false, length = 10)
  private Date                      startDate;

  @Temporal(TemporalType.DATE)
  @Column(name = "end_date", length = 10)
  private Date                      endDate;

  @Column(name = "frequency")
  private Integer                   frequency;

  @Column(name = "receiver_option", nullable = false, length = 50)
  @Enumerated(EnumType.STRING)
  private ReceiverOption            receiverOption;

  @Column(name = "title", nullable = false, length = 100)
  private String                    title;

  @OneToMany(fetch = FetchType.LAZY, mappedBy = "notification")
  @Cascade({ CascadeType.ALL })
  private Set<NotificationReceiver> notificationReceivers = new HashSet<NotificationReceiver>(0);

  public Notification() {
  }

  public Notification(Member member, String note, Date startDate, Date endDate, Integer frequency, ReceiverOption receiverOption, String title, Date createdOn,
      Date lastUpdate, Set<NotificationReceiver> notificationReceivers) {
    this.member = member;
    this.note = note;
    this.startDate = startDate;
    this.endDate = endDate;
    this.frequency = frequency;
    this.receiverOption = receiverOption;
    this.title = title;
    this.createdOn = createdOn;
    this.lastUpdate = lastUpdate;
    this.notificationReceivers = notificationReceivers;
  }

  public Member getMember() {
    return this.member;
  }

  public void setMember(Member member) {
    this.member = member;
  }

  public String getNote() {
    return this.note;
  }

  public void setNote(String note) {
    this.note = note;
  }

  public Date getStartDate() {
    return this.startDate;
  }

  public void setStartDate(Date startDate) {
    this.startDate = startDate;
  }

  public Date getEndDate() {
    return this.endDate;
  }

  public void setEndDate(Date endDate) {
    this.endDate = endDate;
  }

  public Integer getFrequency() {
    return this.frequency;
  }

  public void setFrequency(Integer frequency) {
    this.frequency = frequency;
  }

  public ReceiverOption getReceiverOption() {
    return this.receiverOption;
  }

  public void setReceiverOption(ReceiverOption receiverOption) {
    this.receiverOption = receiverOption;
  }

  public String getTitle() {
    return this.title;
  }

  public void setTitle(String title) {
    this.title = title;
  }

  public Set<NotificationReceiver> getNotificationReceivers() {
    return this.notificationReceivers;
  }

  public void setNotificationReceivers(Set<NotificationReceiver> notificationReceivers) {
    this.notificationReceivers = notificationReceivers;
  }

}
